package com.dianping.cat.home.utilization.transform;

import com.dianping.cat.home.utilization.IEntity;
import com.dianping.cat.home.utilization.IVisitor;
import com.dianping.cat.home.utilization.entity.ApplicationState;
import com.dianping.cat.home.utilization.entity.Domain;
import com.dianping.cat.home.utilization.entity.MachineState;
import com.dianping.cat.home.utilization.entity.UtilizationReport;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  14 */   private Stack<Object> m_objs = new Stack();

  private UtilizationReport m_utilizationReport;


  public DefaultMerger() {}

  public DefaultMerger(UtilizationReport utilizationReport) {
/*  22 */     this.m_utilizationReport = utilizationReport;
/*  23 */     this.m_objs.push(utilizationReport);
  }


/*  27 */   public UtilizationReport getUtilizationReport() { return this.m_utilizationReport; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  35 */     this.m_objs.push(to);
    from.accept(this);
/*  37 */     this.m_objs.pop();
  }


/*  41 */   protected void mergeApplicationState(ApplicationState to, ApplicationState from) { to.mergeAttributes(from); }



/*  45 */   protected void mergeDomain(Domain to, Domain from) { to.mergeAttributes(from); }



/*  49 */   protected void mergeMachineState(MachineState to, MachineState from) { to.mergeAttributes(from); }



/*  53 */   protected void mergeUtilizationReport(UtilizationReport to, UtilizationReport from) { to.mergeAttributes(from); }



  public void visitApplicationState(ApplicationState from) {
/*  58 */     ApplicationState to = (ApplicationState)this.m_objs.peek();

/*  60 */     mergeApplicationState(to, from);
/*  61 */     visitApplicationStateChildren(to, from);
  }


  protected void visitApplicationStateChildren(ApplicationState to, ApplicationState from) {}


  public void visitDomain(Domain from) {
/*  69 */     Domain to = (Domain)this.m_objs.peek();

/*  71 */     mergeDomain(to, from);
/*  72 */     visitDomainChildren(to, from);
  }

  protected void visitDomainChildren(Domain to, Domain from) {
/*  76 */     for (MachineState source : from.getMachineStates().values()) {
/*  77 */       MachineState target = to.findMachineState(source.getId());

/*  79 */       if (target == null) {
/*  80 */         target = new MachineState(source.getId());
/*  81 */         to.addMachineState(target);
      }

/*  84 */       this.m_objs.push(target);
/*  85 */       source.accept(this);
/*  86 */       this.m_objs.pop();
    }

/*  89 */     for (ApplicationState source : from.getApplicationStates().values()) {
/*  90 */       ApplicationState target = to.findApplicationState(source.getId());

/*  92 */       if (target == null) {
/*  93 */         target = new ApplicationState(source.getId());
/*  94 */         to.addApplicationState(target);
      }

/*  97 */       this.m_objs.push(target);
/*  98 */       source.accept(this);
/*  99 */       this.m_objs.pop();
    }
  }


  public void visitMachineState(MachineState from) {
/* 105 */     MachineState to = (MachineState)this.m_objs.peek();

/* 107 */     mergeMachineState(to, from);
/* 108 */     visitMachineStateChildren(to, from);
  }


  protected void visitMachineStateChildren(MachineState to, MachineState from) {}


  public void visitUtilizationReport(UtilizationReport from) {
/* 116 */     UtilizationReport to = (UtilizationReport)this.m_objs.peek();

/* 118 */     mergeUtilizationReport(to, from);
/* 119 */     visitUtilizationReportChildren(to, from);
  }

  protected void visitUtilizationReportChildren(UtilizationReport to, UtilizationReport from) {
/* 123 */     for (Domain source : from.getDomains().values()) {
/* 124 */       Domain target = to.findDomain(source.getId());

/* 126 */       if (target == null) {
/* 127 */         target = new Domain(source.getId());
/* 128 */         to.addDomain(target);
      }

/* 131 */       this.m_objs.push(target);
/* 132 */       source.accept(this);
/* 133 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/utilization/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */